package com.cqeec.service.imp;

import java.sql.Connection;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import javax.swing.JOptionPane;

import com.cqeec.dao.StudentDao;
import com.cqeec.dao.TeacherDao;
import com.cqeec.dao.imp.StudentDaoImp;
import com.cqeec.dao.imp.TeacherDaoImp;
import com.cqeec.domain.Student;
import com.cqeec.domain.Teacher;
import com.cqeec.service.TeacherService;

public class TeacherServiceImpl implements TeacherService {

	@Override
	public Teacher findTeacherByID(Connection conn, Teacher teacher) { 
		TeacherDao dao=new TeacherDaoImp();
		 
		Teacher user = dao.findTeacherByID(conn,teacher.getTeacherNum());
 
		if(user==null) {
			JOptionPane.showMessageDialog(null, "没有该教师", "提示", JOptionPane.ERROR_MESSAGE);
			return null;
		} 
		if(user.getTeacherNum().trim().equals(teacher.getTeacherPwd().trim())) {
			return user;
		} 
		 
		
		return null;
	}


	@Override
	public int addteachers(Connection conn, Teacher teacher) {
		TeacherDao dao=new TeacherDaoImp();
		int rs=dao.addTeacherByID(conn,teacher);
		if(rs==0) {
			JOptionPane.showMessageDialog(null, "添加失败", "提示", JOptionPane.ERROR_MESSAGE);
			return 0;
		} 
		 
		return rs;
	}

	/**
	 * 导入学生数据
	 */
	@Override
	public List<Student> findStudentAll(Connection conn,String courseNum) { 
		StudentDao dao = new StudentDaoImp();
		List<Student>  studentList  = new ArrayList<>();
		try {
			studentList = dao.findStudentByCourseNum(conn, courseNum);
			
			if(studentList==null) {
				JOptionPane.showMessageDialog(null, "导入数据失败 请联系管理员", "提示", JOptionPane.ERROR_MESSAGE);
				return null;
			} 
		} catch (Exception e) { 
			e.printStackTrace();
		}
		return studentList;
	}


	@Override
	public void upateTeacherByTeacherNum(Connection conn, Teacher teacher)  { 
		TeacherDao dao = new TeacherDaoImp();
		
		try {
			dao.upateTeacherByTeacherNum(conn, teacher);
		} catch (Exception e) { 
			e.printStackTrace();
		}
	}

/**
 * 查看请假
 */
	@Override
	public ResultSet getleave(Connection con) {
		TeacherDao dao=new TeacherDaoImp();
		ResultSet rs=dao.getallleave(con);
		if(rs==null) {
			JOptionPane.showMessageDialog(null, "查询失败", "提示", JOptionPane.ERROR_MESSAGE);
		}
		
		
		
		
		return rs;
	}

	

}
